package com.cpp.dao;

import java.util.ArrayList;
import java.util.List;

import com.cpp.bean.Tbl_Sina_waccount;
import com.cpp.db.DBUtils;
import com.cpp.db.ResultRow;

public class Tbl_Sina_waccount_DAO {

	public List<Tbl_Sina_waccount> query(){
		List<Tbl_Sina_waccount> result = new ArrayList<Tbl_Sina_waccount>();
		String sql = "select id,name,uid,addtime,type,sinceid from tbl_sina_waccount where valid = '0'";
		try {
			List<ResultRow> list = DBUtils.query(sql);
			for(ResultRow rr : list){
				Tbl_Sina_waccount waccount = new Tbl_Sina_waccount();
				waccount.setId(rr.getInt(1));
				waccount.setName(rr.getString(2));
				waccount.setUid(rr.getString(3));
				waccount.setAddtime(rr.getDate(4));
				waccount.setType(rr.getString(5));
				waccount.setSinceid(rr.getString(6));
				result.add(waccount);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	public void update(long sinceid,int id){
		String query = "select sinceid from tbl_sina_waccount where id = ?";
		try {
			long oldsinceid = DBUtils.queryLong(query,new Object[]{id});
			if(sinceid > oldsinceid){
				String sql = "update tbl_sina_waccount set sinceid = ? where id = ?";
				Object[] params = new Object[]{Long.toString(sinceid),id};				
				DBUtils.update(sql, params);				
			}
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		
	}
}
